1. Field of the Invention
This invention is related to optimizing code such as, but not limited to, scripting language code. Specifically, but not intended to limit the invention, embodiments of the invention are related to creating optimized code across various virtual machines/runtimes for numerous programming languages which is reusable in browsers or other applications for multiple browsing contexts using a copy-and-update process, creating a new execution context for subsequent runs.
2. Relevant Background
When an application (e.g., a browser) accesses a new browsing context, one or more JavaScript® virtual machines (“VMs”), which are VMs for executing code written in JavaScript® scripting language, may execute segments of JavaScript® scripting language code (which may be referred to herein simply as “a script” or “a JavaScript®”) contained within the browsing context by, for example, initially accessing and executing unoptimized just-in-time compiled (“JITed”) code. A browsing context is an environment which contains information accessible to a JavaScript® such as, but not limited to a web page DOM (document object model) tree. Each web page comprises a particular browser context. Such an operation may be referred to as a slow start-up or a start-up. The JavaScript® VMs may then collect profiling data and optimize the JavaScript® execution using browsing context specific information. Highly optimized JavaScript® ASM (assembly language) code may then be created for each browsing context. Initially executing unoptimized JITed code may cause some JavaScripts® to execute slowly and this slow start-up may prevent an opportunity to use highly optimized JITed code, thereby limiting efficiency.
Furthermore, re-using highly optimized JITed code among browsing contexts is not possible with current architectures unless performance is compromised. For example, efficient optimized code makes assumptions which are checked at runtime in order for the JITed code to perform accurately and effectively. The fastest way to implement these checks is using context-specific data, that is, data from the browsing context which the JavaScript® is a part of. However, code containing context-specific checks cannot be correctly or safely executed in other browsing contexts as doing so may result in memory leaks and unauthorized access to private and context-specific data.